<extend name="common:commonSimpleNewTemplate" />
<block name="main_content">
    <style>
        label{
            display: inline;
        }
    </style>
<div id="">
	<div id="content-header">
		<div id="breadcrumb">
			<a class="tip-bottom" href="index.html"
				data-original-title="Go to Home"><i class="icon-home"></i> 首页</a>
			<a href="#">经销商</a> <a class="current" href="#">经销商订单提交</a>
		</div>
	</div>
	<div class="container-fluid">
		<div class="row-fluid">
			<div class="span12">
				<div class="widget-box">
					<div class="widget-title">
						<span class="icon"> <i class="icon-info-sign"></i>
						</span>
						<h5>收货信息</h5>
					</div>
					<div class="widget-content nopadding" >
						<br/>
						  <div class="controls controls-row" style="margin-left:200px;">
				            	<label style=" margin-left: 10px;">经销商编号：</label><input style="width:200px;" value="{$dealer_en.dealer_id}" type="text" class="m-wrap" readonly>
				            	<label style=" margin-left: 10px;">经销商姓名：</label><input style="width:200px;" value="{$dealer_en.dealer_name}" type="text" class="m-wrap" readonly >
				            	<label style="margin-left: 10px;">折 &nbsp;&nbsp;扣&nbsp;&nbsp; 率：</label><input style="width:200px;" value="{$dealer_en.discount_rate}" type="text" class="m-wrap" readonly>
				          </div>
                        <div class="controls controls-row" style="margin-left:200px;">
                            <label style=" margin-left: 10px;">账&nbsp;户&nbsp;&nbsp;余&nbsp;额：</label><input style="width:200px;" value="{$dealer_en.amount}" type="text" class="m-wrap" readonly>
                            <label style=" margin-left: 10px;">返&nbsp;现&nbsp;&nbsp;余&nbsp;额：</label><input style="width:200px;" value="{$dealer_en.cashback_amount}" type="text" class="m-wrap" readonly >
                        </div>
					</div>
				</div>
			</div>
		</div>
	
	<div class="row-fluid">
      <div class="span12">
        <div class="widget-box">
          <div class="widget-title"> <span class="icon"> <i class="icon-th"></i> </span>
            <h5>收货地址</h5>
          </div>
          <div class="widget-content nopadding">
	          <div style="padding: 5px; cursor: pointer; width: 100%;">
	            <div style="margin-bottom:5px;" class="alert alert-error alert-block">
	              <h4 class="alert-heading">{$user_address.consignee_name}【{$user_address.consignee_cellphone}】</h4>
	              <span style="font-size:16px;">{$user_address.consignee_province}{$user_address.consignee_city}{$user_address.consignee_district}{$user_address.consignee_address}</span></div>
	          </div>
          </div>
      </div>

    </div>
  </div>
  
  	<div class="row-fluid"  style="display:none">
               <input id='dealer_id' value='{$dealer_id}'>
               <input id='select_address_id' value='{$select_address_id}'>
               <input id='lst_sku' value='{$lst_sku}'>
     </div>
  
  <div class="row-fluid">
      <div class="span12">
        <div class="widget-box">
          <div class="widget-title"> <span class="icon"> <i class="icon-th"></i> </span>
            <h5>商品清单</h5>
          </div>
          <div class="widget-content">
	          <ul class="recent-posts">
	          <volist name="lst_product" id="product"
									empty="暂时没有数据">
			  <li>
                <div class="user-thumb" style="margin-left:100px">
					<img width="40" height="40" src="http://o.whaley.cn/Public/images/style/small/55.jpg" alt="User">
				</div>
                <div class="article-post">
				  <div style="margin-right:100px;" class="fr">
					  小计：￥<span class='discount_total_price' style="color:red;">{$product.payment_total_price}</span>
				  </div>
				  <div style="margin-right:50px;" class="fr">
                  	X<span sku_id='{$product.sku_id}' is_rebate='{$product.is_rebate}' class="qty" style="color:red;">{$product.qty}</span>
				  </div>
                    <span style="color:red;" class="user-info">
      						<if condition="($product.is_rebate eq '0')">
      						  正价商品，无返点
      						<else/>
     						 </if>

     					<if condition="($product.is_rebate eq '1')">
      						  参与返点
      						<else/>
     						 </if>
                </span>				  <div style="margin-right:150px;" class="fr">
					  开 单 价：￥<span class='sale_price' style="text-decoration:line-through;">{$product.sale_price}</span><br>
					  溢&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;价：￥<span class="discount_price" style="color:red;">{$product.payment_price}</span><br>
					</div>
                  <span class="user-info" >经销商专享</span>
                  <p style="font-size:16px;">{$product.sku_name} </p>
                </div>
              </li>					
				</volist>


              <li id="li_payment_type">
                <div class="article-post" style="height: 60px;font-size:16px;">
				  <div class="" style="float:right;">
				  			<label class="control-label">支付方式：</label>
								<div class="controls">
								<select id="payment_type" name="payment_type" style="width:220px;" >
                                    <option value="3">余额支付</option>
								</select>
								</div>
					</div>
                </div>
              </li>

              <li id="li_amountPayment">
                  <div class="article-post" style="height: 100px;font-size:16px;">
                      <div class="" style="float:right;">
                          <label class="control-label">余额使用：</label>
                          <div class="controls">
                              <p>返现余额还剩{$dealer_en.cashback_amount}【本次最多可用<span id="span_can_use_dealear_cashback_amount">{$can_use_dealear_cashback_amount}</span>元】：<input style="height:30px;" can_use_amount="" id="txtDealer_cashback_amount" type="text" value="0"/><a id="btnCashbackAmount" class="btn btn-success">使用</a></p>
                          </div>
                      </div>
                  </div>
              </li>
			  <li>
				  <div style="height: 150px;font-size:16px;" class="article-post">
					  <div style="float:right;" class="">
						  商品数量：<span id='qty_span' style="color:red;">{$total_qty}</span><br>
						  商品金额：￥<span id='totolAmount_span' style="text-decoration:line-through;">{$goods_total_amount}</span><br>
						  订单金额：￥<span id='orderAmount_span' style="color:red;">{$payment_total_amount}</span><br>
						  折扣金额：￥<span id='discountAmount_span' style="">{$discount_amount}</span><br/>
                          账户余额支付：￥<span id='dealear_amount' style="">{$can_use_dealear_amount}</span><br/>
                          返现余额支付：￥<span id='dealear_cashback_amount' style="">0.00</span><br/>
						  <span style="color:red;">支付金额：￥<span id='paymentAmount_span' style="color:red;">{$payment_total_amount}</span></span><br/>
					  </div>
				  </div>
			  </li>

              <li>
                <div class="article-post" style="height: 30px;font-size:16px;">
				   <div class="" style="margin-left:50px;float:left;">
					 <label style="display: inline; margin-left: 10px;">订单备注：</label><input id="remark" type="text" placeholder="" class="m-wrap" style="width:80%;">
					</div>
                </div>
              </li>
              <li>
                  <div class="article-post" style="height: 30px;font-size:16px;">
				   <div class="" style="margin-left:50px;float:left;">
					 <label style="display: inline; margin-left: 10px;">订单上浮金额（加上）：</label><input id="addDiscountAmount" type="text" placeholder="" class="m-wrap" style="width:80%;">
					</div>
                </div>
              </li>
              <li style="text-align:center;">
                <button class="btn btn-danger btn-large" id='submitOrder' type="submit">确认，提交订单</button>
                  <button class="btn btn-primary btn-large" id='backSubmit' type="submit">重新选</button>
              </li>
            </ul>
          </div>
      </div>

    </div>
  </div>

</div>
	</div>
</block>

<block name="js_content">
<script type="text/javascript">
var can_use_dealear_amount = {$can_use_dealear_amount};
DealerCheckOutPage = {
		'BindEvent': function(){
			$('#submitOrder').bind('click', function(){
				var dealer_id       = $('#dealer_id').val();
				var select_address_id=$('#select_address_id').val();
				var sku_list_str    = $('#lst_sku').val();
				var remark          = $('#remark').val();
				var payment_type    = $('#payment_type').val();
                var dealer_cashback_amount   = $('#txtDealer_cashback_amount').val();

				if(payment_type==''){
					alert('请选择支付方式');
					return;
				}

				//浮动金额
				var addDiscountAmount = $('#addDiscountAmount').val();
				var subDiscountAmount = $('#subDiscountAmount').val();
				if(addDiscountAmount!=''&&isNaN(addDiscountAmount)){
					alert('上浮价格不是数字');
					return;
				}
				
				if(parseFloat(addDiscountAmount)<0){
					alert('上浮价格不能小于0');
					return;
				}
				
				
				var subDiscountAmount='';
				var dealer_channel=1;
				var result=DealerService.SubmitDealerOrder(dealer_id,
                        select_address_id,sku_list_str,remark,payment_type,
                        addDiscountAmount,subDiscountAmount,dealer_channel,
                        dealer_cashback_amount
                );
				if(result.IsSuccess == 0){
					alert(result.ErrorMsg);
					return;
				}
				else{
				    window.location.href = result.Result;
				}
			});


            //支付方式变更
            $('#payment_type').bind('change', function(){
                var payment_type    = $('#payment_type').val();
                alert('支付方式变更，请重新检查支付金额！');
                if(payment_type == 3){
                    //余额支付
                    $('#dealear_amount').text(can_use_dealear_amount);
                    $('#txtDealer_cashback_amount').val(0);
                    $('#li_amountPayment').show();
                }
                else{
                    $('#dealear_amount').text(0);
                    $('#txtDealer_cashback_amount').val(0);
                    $('#li_amountPayment').hide();
                    $('#dealear_amount').text(0);
                    $('#dealear_cashback_amount').text(0);
                }
            });


            //使用后返余额
            $('#btnCashbackAmount').bind('click', function(){
            	
                var dealear_cashback_amount = parseFloat($('#txtDealer_cashback_amount').val());
                var order_amount  = parseFloat($('#orderAmount_span').text());
                var can_use_dealear_cashback_amount = parseFloat($('#span_can_use_dealear_cashback_amount').text());
                if(dealear_cashback_amount > can_use_dealear_cashback_amount){
                	alert('超出返现金额使用限制');
                	$('#txtDealer_cashback_amount').val($('#txtDealer_cashback_amount').attr('can_use_amount'));
                	return;
                }
                
                $('#txtDealer_cashback_amount').attr('can_use_amount', dealear_cashback_amount);
                
                $('#dealear_amount').text(parseFloat(order_amount - dealear_cashback_amount).toFixed(2));
                $('#dealear_cashback_amount').text(dealear_cashback_amount);

            });


			$('#backSubmit').bind('click', function(){
				 history.go(-1);
			});
		} 
		
};


$(document).ready(function(){
	DealerCheckOutPage.BindEvent();
});


</script>
</block>